package cmd

import (
	"gitee.com/xuender/oils/logs"
	"gitee.com/xuender/se"
	"github.com/spf13/cobra"
)

// nolint: gochecknoinits
func init() {
	indexCmd := &cobra.Command{
		Use:     "index [目录或文件]",
		Short:   "索引目录或文件",
		Long:    `对文件或目录进行索引`,
		Aliases: []string{"i"},
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) == 0 {
				logs.Error("缺少索引目录或文件")
				_ = cmd.Usage()

				return
			}

			app := se.InitApp(se.NewContext(cmd))
			defer app.Close()

			app.Index(args)
		},
	}

	rootCmd.AddCommand(indexCmd)
}
